package com.hupu.jrs.ui.pmdetail

import android.content.Context
import android.content.Intent
import android.support.v7.widget.Toolbar
import butterknife.BindView
import butterknife.ButterKnife
import com.hupu.jrs.R
import com.hupu.jrs.injector.HasComponent
import com.hupu.jrs.ui.BaseSwipeBackActivity

/**
 * Created by sll on 2016/5/6.
 */
class PmDetailActivity : BaseSwipeBackActivity(), HasComponent<PmDetailComponent> {

    @BindView(R.id.toolbar)
    internal var toolbar: Toolbar? = null

    override var component: PmDetailComponent? = null
        private set
    private var uid: String? = null

    protected override val isApplyStatusBarTranslucency: Boolean
        get() = true

    protected override val isApplyStatusBarColor: Boolean
        get() = true

    override fun initContentView(): Int {
        return R.layout.base_content_toolbar_layout
    }

    override fun initInjector() {
        uid = getIntent().getStringExtra("uid")
        component = DaggerPmDetailComponent.builder()
                .applicationComponent(getApplicationComponent())
                .activityModule(getActivityModule())
                .pmDetailModule(PmDetailModule(uid))
                .build()
    }

    override fun initUiAndListener() {
        ButterKnife.bind(this)
        initToolBar(toolbar)
        val name = getIntent().getStringExtra("name")

        setTitle(name)
        getFragmentManager().beginTransaction()
                .replace(R.id.content, PmDetailFragment.newInstance(uid.toString()))
                .commit()
    }

    companion object {
        fun startActivity(mContext: Context, uid: String, name: String) {
            val intent = Intent(mContext, PmDetailActivity::class.java)
            intent.putExtra("uid", uid)
            intent.putExtra("name", name)
            mContext.startActivity(intent)
        }
    }
}
